package org.metawatch.manager;

public class _4911StateMachine {
	
	public static final int STATE_HOME = 1;
	public static final int STATE_MAINMENU = 2;
	public static final int STATE_PEDOMETER = 5;
	public static final int STATE_STOPWATCH = 6;
	public static final int STATE_GPS = 7;
	public static final int STATE_MUSIC = 8;
	
	public static final int ACTION_PEDOMETER_START = 20;
	public static final int ACTION_PEDOMETER_STOP = 21;
	public static final int ACTION_PEDOMETER_RESET = 22;
	
	public static final int ACTION_STOPWATCH_START = 30;
	public static final int ACTION_STOPWATCH_STOP = 31;
	public static final int ACTION_STOPWATCH_RESET = 32;
	
	public static final int ACTION_MUSIC_TOGGLE = 40;
	public static final int ACTION_MUSIC_NEXT = 41;
	public static final int ACTION_MUSIC_PREV = 42;
	
	public int currentState;
	
	public _4911StateMachine(){
		currentState = STATE_HOME;
	}
	
	
	/*
	 * This function will take the next button input of the watch
	 * and change states or give actions accordingly.
	 * 
	 * */
	public int button_input(byte button){
		if(currentState == STATE_HOME) {
			if(button == 0x0){
				
			} else if(button == 0x1) {

			} else if(button == 0x2) {

			} else if(button == 0x3) {
				return changeState(STATE_MAINMENU);
			} else if(button == 0x4) {
				
			} else if(button == 0x5) {
				return changeState(STATE_PEDOMETER);
			}
			
		} else if(currentState == STATE_MAINMENU) {
			if(button == 0x0){
				
			} else if(button == 0x1) {
			
			} else if(button == 0x2) {
				
			} else if(button == 0x3) {
				return changeState(STATE_HOME);
			} else if(button == 0x4) {
				
			} else if(button == 0x5) {
				
			}

			
		} else if(currentState == STATE_PEDOMETER) {
			if(button == 0x0){
				return ACTION_PEDOMETER_START;
			} else if(button == 0x1) {
				return ACTION_PEDOMETER_STOP;
			} else if(button == 0x2) {
				
			} else if(button == 0x3) {
				return changeState(STATE_HOME);
			} else if(button == 0x4) {
				return ACTION_PEDOMETER_RESET;
			} else if(button == 0x5) {
				return changeState(STATE_STOPWATCH);
			}
			
		} else if(currentState == STATE_STOPWATCH) {	
			if(button == 0x0){
				return ACTION_STOPWATCH_START;
			} else if(button == 0x1) {
				return ACTION_STOPWATCH_STOP;
			} else if(button == 0x2) {
				
			} else if(button == 0x3) {
				return changeState(STATE_HOME);
			} else if(button == 0x4) {
				return ACTION_STOPWATCH_RESET;
			} else if(button == 0x5) {
				return changeState(STATE_MUSIC);
			}
			
		} else if(currentState == STATE_GPS) {	
			if(button == 0x0){
				
			} else if(button == 0x1) {
			
			} else if(button == 0x2) {
				
			} else if(button == 0x3) {
				return changeState(STATE_HOME);
			} else if(button == 0x4) {
				
			} else if(button == 0x5) {
				return changeState(STATE_PEDOMETER);
			}
			
		} else if(currentState == STATE_MUSIC) {
			if(button == 0x0){
				return ACTION_MUSIC_TOGGLE;
			} else if(button == 0x1) {
				return ACTION_MUSIC_PREV;
			} else if(button == 0x2) {
				
			} else if(button == 0x3) {
				return changeState(STATE_HOME);
			} else if(button == 0x4) {
				return ACTION_MUSIC_NEXT;
			} else if(button == 0x5) {
				return changeState(STATE_GPS);
			}
			
		}
		
		return 0;
	}
	
	private int changeState(int state){
		currentState = state;
		return state;
	}

}
